package cn.melonlib.nars.cores.web.ctrl;

import cn.melonlib.cores.commons.comp.web.ctrl.BasicController;
import cn.melonlib.cores.graphql.comp.web.proxy.GraphqlWebProxy;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

@RestController
@RequestMapping(path = "/")
public class MainController extends BasicController {

    @Resource
    private GraphqlWebProxy graphqlWebProxy;



    @CrossOrigin(originPatterns = "*")
    @ResponseBody
    @RequestMapping(value = "provider", method = {RequestMethod.POST}, produces = APPLICATION_JSON_UTF8_VALUE)
    public Object provider(@RequestBody Map body, HttpServletRequest request) throws Exception {
        return graphqlWebProxy.executeGraphQL(body, request);
    }

    @GetMapping(value = "provider.api", produces = APPLICATION_JSON_UTF8_VALUE)
    public String providerApi(HttpServletRequest request, HttpServletResponse response)throws Exception{
        return graphqlWebProxy.providerMap(request,response);
    }


}
